home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: clamage@Eng.sun.com (Steve Clamage)
- Newsgroups: comp.std.c++
- Subject: Re: pointer conversions from the null pointer
- Date: 20 Feb 1996 21:32:36 GMT
- Organization: Sun Microsystems Inc.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4gddco$cqv@engnews1.Eng.Sun.COM>
- References: <baluDn1pGL.8J1@netcom.com>
- Reply-To: clamage@Eng.sun.com
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Type: text
- X-Nntp-Posting-Host: taumet.eng.sun.com
- Content-Length: 928
- X-Lines: 37
- Originator: clamage@taumet
-
- In article 8J1@netcom.com, balu@netcom.com (Balasubramanian) writes:
- >Given the following:
-
- >class A {};
- >class B : public A {};
- >class C : public B {};
-
- >void foo(A*) { ... }
-
- >void foo(C*) { ... }
-
- >int main() {foo(0); return 0;}
-
- >How is the call to foo() in main() to be resolved? It seemed obvious
- >to me that the call should be ambiguous ...
-
- It seems obvious to me too. The null pointer constant is an exact match
- for any pointer, so there is no reason to prefer either version of foo.
-
- There is a preference associated with class hierarchies. For example:
- class X { ... };
- class Y : public X { ... };
- class Z : public Y { ... };
- void foo(X*);
- void foo(Y*);
-
- Z* pz = ...;
- foo(pz);
-
- A Z* can be converted to either a Y* or an X*, but Y* is preferred. This
- case does not apply to null pointer constants, however, since a null
- pointer constant does not have type Z*.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
-
-
-
- [ To submit articles: Try just posting with your newsreader.
- If that fails, use mailto:std-c++@ncar.ucar.edu
- FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
- Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-